Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ analyzer:
exclude:
- doc/tutorials/chapter_9/rohd_vf_example
- rohd_devtools_extension
- rohd_extension/dart

# keep up to date, matching https://dart.dev/tools/linter-rules/all
# some lints are not yet available, so disabled and marked with [not currently recognized]
Expand Down
122 changes: 56 additions & 66 deletions doc/tutorials/chapter_6/answers/exercise_2_n_bit_subtractor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import '../../chapter_3/answers/helper.dart';
import '../../chapter_5/answers/full_subtractor.dart';

class FullSubtractorComb extends FullSubtractor {
@override
FullSubtractorComb(super.a, super.b, super.borrowIn) {
// Declare input and output
final a = input('a');
Expand All @@ -19,39 +18,19 @@ class FullSubtractorComb extends FullSubtractor {
final borrowOut = addOutput('borrow_comb');

Combinational([
Case([a, b, borrow].swizzle(), [
CaseItem(Const(bin('000'), width: 3), [
diff < 0,
borrowOut < 0,
]),
CaseItem(Const(bin('001'), width: 3), [
diff < 1,
borrowOut < 1,
]),
CaseItem(Const(bin('010'), width: 3), [
diff < 1,
borrowOut < 1,
]),
CaseItem(Const(bin('011'), width: 3), [
diff < 0,
borrowOut < 1,
]),
CaseItem(Const(bin('100'), width: 3), [
diff < 1,
borrowOut < 0,
]),
CaseItem(Const(bin('101'), width: 3), [
diff < 0,
borrowOut < 0,
]),
CaseItem(Const(bin('110'), width: 3), [
diff < 0,
borrowOut < 0,
])
], defaultItem: [
diff < 1,
borrowOut < 1
])
Case(
[a, b, borrow].swizzle(),
[
CaseItem(Const(bin('000'), width: 3), [diff < 0, borrowOut < 0]),
CaseItem(Const(bin('001'), width: 3), [diff < 1, borrowOut < 1]),
CaseItem(Const(bin('010'), width: 3), [diff < 1, borrowOut < 1]),
CaseItem(Const(bin('011'), width: 3), [diff < 0, borrowOut < 1]),
CaseItem(Const(bin('100'), width: 3), [diff < 1, borrowOut < 0]),
CaseItem(Const(bin('101'), width: 3), [diff < 0, borrowOut < 0]),
CaseItem(Const(bin('110'), width: 3), [diff < 0, borrowOut < 0]),
],
defaultItem: [diff < 1, borrowOut < 1],
),
]);
}

Expand Down Expand Up @@ -92,41 +71,49 @@ class NBitFullSubtractor extends Module {

Future<void> main() async {
group('Full Subtractor', () {
test('should return True when cas conditionals matched truth table',
() async {
final a = Logic();
final b = Logic();
final bIn = Logic();

final fsComb = FullSubtractorComb(a, b, bIn);
await fsComb.build();

for (var i = 0; i <= 1; i++) {
for (var j = 0; j <= 1; j++) {
for (var k = 0; k <= 1; k++) {
a.put(i);
b.put(j);
bIn.put(k);

final res = fsTruthTable(i, j, k);

final actualDiff = fsComb.fsResult.diff.value.toInt();
final actualBOut = fsComb.fsResult.borrow.value.toInt();

final expectedDiff = res.diff;
final expectedBOut = res.borrowOut;

expect(actualDiff, expectedDiff,
test(
'should return True when cas conditionals matched truth table',
() async {
final a = Logic();
final b = Logic();
final bIn = Logic();

final fsComb = FullSubtractorComb(a, b, bIn);
await fsComb.build();

for (var i = 0; i <= 1; i++) {
for (var j = 0; j <= 1; j++) {
for (var k = 0; k <= 1; k++) {
a.put(i);
b.put(j);
bIn.put(k);

final res = fsTruthTable(i, j, k);

final actualDiff = fsComb.fsResult.diff.value.toInt();
final actualBOut = fsComb.fsResult.borrow.value.toInt();

final expectedDiff = res.diff;
final expectedBOut = res.borrowOut;

expect(
actualDiff,
expectedDiff,
reason: 'a: $a, b: $b, bIn: $bIn'
' actualDiff: $actualDiff, expectedDiff: $expectedDiff');
' actualDiff: $actualDiff, expectedDiff: $expectedDiff',
);

expect(actualBOut, expectedBOut,
expect(
actualBOut,
expectedBOut,
reason: 'a: $a, b: $b, bIn: $bIn'
' actualBOut: $actualBOut, expectedBOut: $expectedBOut');
' actualBOut: $actualBOut, expectedBOut: $expectedBOut',
);
}
}
}
}
});
},
);
});

test(
Expand All @@ -145,7 +132,10 @@ Future<void> main() async {
a.put(randA);
b.put(randB);

expect(mod.result.value.toInt(), equals(minusResult),
reason: 'randA: $randA, randB: $randB, addResult: $minusResult');
expect(
mod.result.value.toInt(),
equals(minusResult),
reason: 'randA: $randA, randB: $randB, addResult: $minusResult',
);
});
}
4 changes: 4 additions & 0 deletions rohd_extension/.markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"MD013": { "tables": false, "code_blocks": false },
"MD060": false
}
98 changes: 98 additions & 0 deletions rohd_extension/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Makefile for the ROHD VS Code Extension (rohd_extension)
#
# Targets:
# compile - Compile TypeScript sources to out/
# install - Compile and install to remote VS Code Server (default)
# install-local - Compile and install to local VS Code
# install-remote - Compile and install to remote VS Code Server
# clean - Remove compiled output and packaged .vsix files
# real-clean - clean + remove node_modules, lock files, .dart_tool
# help - Show this help

ROOT := $(shell pwd)
TS_SOURCES := $(shell find $(ROOT)/src -name '*.ts' 2>/dev/null)

# Read name/version from package.json
PKG_NAME := $(shell node -p "require('./package.json').name")
PKG_VERSION := $(shell node -p "require('./package.json').version")
PKG_PUBLISHER := $(shell node -p "require('./package.json').publisher")

# VS Code Server extension directory (remote dev container)
REMOTE_EXT_DIR := $(HOME)/.vscode-server/extensions/$(PKG_PUBLISHER).$(PKG_NAME)-$(PKG_VERSION)
# Local VS Code extension directory
LOCAL_EXT_DIR := $(HOME)/.vscode/extensions/$(PKG_PUBLISHER).$(PKG_NAME)-$(PKG_VERSION)

# Stamp file to track last successful compile
COMPILE_STAMP := out/.compile-stamp

.PHONY: all help compile install install-local install-remote clean real-clean

all: install

help:
@echo "ROHD VS Code Extension - Build Targets"
@echo ""
@echo " compile - Compile TypeScript to out/"
@echo " install - Compile and install to remote server (default)"
@echo " install-local - Compile and install to local VS Code"
@echo " install-remote - Compile and install to remote VS Code Server"
@echo " clean - Remove compiled output and .vsix files"
@echo " real-clean - clean + node_modules, lock files, .dart_tool"
@echo ""
@echo "Extension: $(PKG_PUBLISHER).$(PKG_NAME) v$(PKG_VERSION)"
@echo "Remote: $(REMOTE_EXT_DIR)"

# ---------------------------------------------------------------------------
# Compile
# ---------------------------------------------------------------------------

$(COMPILE_STAMP): $(TS_SOURCES) tsconfig.json package.json
@echo "Compiling TypeScript..."
@npx tsc -p ./
@touch $(COMPILE_STAMP)

compile: $(COMPILE_STAMP)

# ---------------------------------------------------------------------------
# Install
# ---------------------------------------------------------------------------

install-remote: compile
@if [ -d "$(REMOTE_EXT_DIR)" ]; then \
echo "Installing to $(REMOTE_EXT_DIR)/out/..."; \
cp out/*.js out/*.js.map "$(REMOTE_EXT_DIR)/out/"; \
echo "Done. Reload the VS Code window to pick up changes."; \
else \
echo "ERROR: Extension not found at $(REMOTE_EXT_DIR)"; \
echo "Install the extension first via VS Code, then use this target to update."; \
exit 1; \
fi

install-local: compile
@if [ -d "$(LOCAL_EXT_DIR)" ]; then \
echo "Installing to $(LOCAL_EXT_DIR)/out/..."; \
cp out/*.js out/*.js.map "$(LOCAL_EXT_DIR)/out/"; \
echo "Done. Reload the VS Code window to pick up changes."; \
else \
echo "ERROR: Extension not found at $(LOCAL_EXT_DIR)"; \
echo "Install the extension first via VS Code, then use this target to update."; \
exit 1; \
fi

install: install-remote

# ---------------------------------------------------------------------------
# Clean
# ---------------------------------------------------------------------------

clean:
@echo "Cleaning compiled output and .vsix files..."
@rm -rf out/
@rm -f *.vsix

real-clean: clean
@echo "Removing node_modules, lock files, and Dart build artifacts..."
@rm -rf node_modules/
@rm -f package-lock.json
@rm -rf dart/.dart_tool/
@rm -f dart/pubspec.lock
Loading
Loading