Feb 17, 2025

AIOS concept: OS by AI agents

Artificial Intelligence Operating System

Introduction to AIOS

An AIOS (Artificial Intelligence Operating System) is a conceptual operating system designed to facilitate the development, deployment, and management of applications entirely driven by artificial intelligence (AI) agents. These agents leverage the power of various large language models (LLMs), machine learning frameworks, and other AI technologies to automate tasks, generate code, optimize workflows, and provide intelligent decision-making capabilities.

The goal of an AIOS is to abstract away much of the complexity involved in software development, allowing developers to focus on high-level design while delegating low-level implementation details to AI agents. This could revolutionize how software is built, tested, and deployed, making it more accessible to non-experts and accelerating innovation.


Read on  

  Mar 20, 2020

Compiler - LLVM, GCC and more

Let’s talk about Swift compiler.

what is swift runtime? What compiler does swift uses? Can you draw a flow diagram of how a typical swift code like if (true) { print(“hello, world!”) } goes through various stages of compile, run time, finally to the machine code?

1. What is the Swift Runtime?

The Swift runtime is a collection of libraries and system components that support the execution of Swift programs. It provides essential functionality such as memory management, object lifecycle management, protocol conformance, and dynamic dispatch.

Key features of the Swift runtime include:

  • Memory Management: Implements Automatic Reference Counting (ARC) to manage the allocation and deallocation of objects.
  • Dynamic Dispatch: Handles method calls for classes and protocols at runtime.
  • Protocol Conformance: Resolves protocol witness tables dynamically when needed.
  • Error Handling: Provides mechanisms for throwing, catching, and propagating errors.
  • Standard Library Integration: Includes the Swift Standard Library (Swift module), which provides fundamental types like String, Array, and Dictionary.

The runtime is part of the operating system on Apple platforms starting with Swift 5.0, thanks to ABI stability. This means apps no longer need to bundle the Swift runtime, reducing their size and improving compatibility across OS versions.


Read on  

  Mar 17, 2020

Structural Design Patterns in iOS

The wikipedia definition of a software design pattern is

A reusable solution to a commonly occuring problem in the context of software design.

Gang of four book in 1994 formalised a number of design patterns. Here we are going to talk more specifically about the common design patterns when it comes to iOS app development.

This is different from the architectural design patterns, MVC or MVVM or Viber or clean architecture.

Structural design patterns are more about managing the piece of codes in reusable way.

Let’s summarize them:

Read on  

  Mar 12, 2020

Dynamic vs Static

When someone says something is dynamic, it usually means things could change. Dynamic array, meaning the content of the array could change, or a dynamic system could mean a system that is robust and can adapt to different input scenario.

So, what does it mean for a framework to be a dynamic framework, or static framework? Or when someone says Python is a dynamically typed language but Swift is a statically typed language?

Let’s dive in.

Read on  

  Mar 26, 2019

Deadlock example

Deadlock is a situation when two or more threads are waiting on each other to be completed causing both to be locked and not able to continue.

A practical example of a deadlock is

Let’s see an example in swift.

here, the the queue is exeucting with q.async first, inside the block it calls for q.sync. So the outer block can only complete when the inner block q.sync is finished, but q.sync cannot start, because it is a sync block unless the thread is free. This results in a deadlock and the process will crash.

import Foundation

class Resource {
	
	private(set) var value: Int
	
	private let q = DispatchQueue(label: "myQueue")
	
	init(_ value: Int) {
		self.value = value
	}

	// Deadlock
	func set(_ value: Int) {
		q.async {
			print("async")
			self.q.sync {
				self.value = value
				print("sync") 	 	// outer block is waiting for this inner block to complete,
        							// inner block won't start before outer block finishes
        							// => deadlock
			}
			print("finished") // this will never be reached
		}
	}
}

let r = Resource(100)
r.set(200)

print("final value \(r.value)")

// Output
// async
// Execution Interrupted due to deadlock
Read on